package o;

import androidx.annotation.NonNull;
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class e extends ThreadPoolExecutor {
    private static final int ˊ = ˎ;
    private static final int ˎ = (ˏ + 1);
    private static final int ˏ = Runtime.getRuntime().availableProcessors();
    private static e ॱ;

    static class b implements ThreadFactory {
        private static final AtomicInteger ˋ = new AtomicInteger(1);
        private final ThreadGroup ˊ;
        private final String ˏ;
        private final AtomicInteger ॱ = new AtomicInteger(1);

        public b() {
            SecurityManager securityManager = System.getSecurityManager();
            this.ˊ = securityManager != null ? securityManager.getThreadGroup() : Thread.currentThread().getThreadGroup();
            this.ˏ = "HwSkinner task pool No." + ˋ.getAndIncrement() + ", thread No.";
        }

        public Thread newThread(@NonNull Runnable runnable) {
            String str = this.ˏ + this.ॱ.getAndIncrement();
            fmq.ˊ("Thread production, name is [" + str + "]");
            Thread thread = new Thread(this.ˊ, runnable, str, 0);
            if (thread.isDaemon()) {
                thread.setDaemon(false);
            }
            if (thread.getPriority() != 5) {
                thread.setPriority(5);
            }
            thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler(this) {
                final /* synthetic */ b ˋ;

                {
                    this.ˋ = r1;
                }

                public void uncaughtException(Thread thread, Throwable th) {
                    fmq.ˊ("Running task appeared exception! Thread [" + thread.getName() + "], because [" + th.getMessage() + "]");
                }
            });
            return thread;
        }
    }

    private e(int i, int i2, long j, TimeUnit timeUnit, BlockingQueue<Runnable> blockingQueue, ThreadFactory threadFactory) {
        super(i, i2, j, timeUnit, blockingQueue, threadFactory, new RejectedExecutionHandler() {
            public void rejectedExecution(Runnable runnable, ThreadPoolExecutor threadPoolExecutor) {
                fmq.ˎ("Task rejected, too many task!");
            }
        });
    }

    public static e ˏ() {
        if (ॱ == null) {
            synchronized (e.class) {
                if (ॱ == null) {
                    ॱ = new e(ˎ, ˊ, 30, TimeUnit.SECONDS, new ArrayBlockingQueue(64), new b());
                }
            }
        }
        return ॱ;
    }

    protected void afterExecute(Runnable runnable, Throwable th) {
        super.afterExecute(runnable, th);
        if (th == null && (runnable instanceof Future)) {
            try {
                ((Future) runnable).get();
            } catch (Throwable e) {
                th = e;
            } catch (ExecutionException e2) {
                th = e2.getCause();
            } catch (InterruptedException e3) {
                Thread.currentThread().interrupt();
            }
        }
        if (th != null) {
            fmq.ˎ("Running task appeared exception! Thread [" + Thread.currentThread().getName() + "], because [" + th.getMessage() + "]\n" + th.getStackTrace());
        }
    }
}
